(defun digits(n)
  (loop for i = n then (floor (/ i 10))
       while (> i 0)
       counting i into sum
       finally (return sum)))

(defun validp (n)
  (loop for i from 2 to 100
     for pow = (digits (expt n i)) then (digits (expt n i))
     when (= i pow) do (return (cons (expt n i) i))
     when (< i pow) do (return nil)
     finally (return nil)))

(defun probl063 (a b)
  (loop for i from 1 to a
     sum (loop for j from 1 to b
	      for digs = (digits (expt i j)) then (digits (expt i j))
	    until (> digs j)
	    when (= digs j)
	    count i)))

(probl063 500 500)
